<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D圣诞树</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            overflow: hidden;
            background: #2d5a27;
        }

        canvas {
            width: 100vw;
            height: 100vh;
        }

        .loading {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-size: 1.2em;
            font-family: Arial, sans-serif;
            text-align: center;
        }

        .loading .progress {
            width: 200px;
            height: 4px;
            background: rgba(255, 255, 255, 0.3);
            margin-top: 10px;
            border-radius: 2px;
        }

        .loading .progress-bar {
            width: 0%;
            height: 100%;
            background: white;
            border-radius: 2px;
            transition: width 0.3s ease;
        }

        .music-control {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .music-control:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .music-control i {
            color: white;
            font-size: 20px;
        }

        /* 添加放大查看相框的样式 */
        .photo-viewer {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.8);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .photo-viewer.active {
            display: flex;
            opacity: 1;
        }

        .photo-viewer img {
            max-width: 90vw;
            max-height: 90vh;
            object-fit: contain;
            transform: scale(0.8);
            opacity: 0;
            transition: all 0.3s ease;
        }

        .photo-viewer .close-btn {
            position: absolute;
            top: 20px;
            right: 20px;
            color: white;
            font-size: 30px;
            cursor: pointer;
            background: none;
            border: none;
            padding: 10px;
            transition: transform 0.3s ease;
        }

        .photo-viewer .close-btn:hover {
            transform: scale(1.1);
        }

        .photo-viewer .nav-btn {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            color: white;
            font-size: 24px;
            cursor: pointer;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            padding: 15px;
            border-radius: 50%;
            transition: all 0.3s ease;
        }

        .photo-viewer .nav-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        .photo-viewer .prev-btn {
            left: 20px;
        }

        .photo-viewer .next-btn {
            right: 20px;
        }

        /* 添加情书弹窗样式 */
        .love-letter {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) scale(0.9);
            width: 300px;
            background: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
            z-index: 1000;
        }

        .love-letter.active {
            opacity: 1;
            visibility: visible;
            transform: translate(-50%, -50%) scale(1);
        }

        .love-letter .close-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            background: none;
            border: none;
            font-size: 20px;
            cursor: pointer;
            color: #ff4444;
            padding: 5px;
            transition: transform 0.3s ease;
        }

        .love-letter .close-btn:hover {
            transform: scale(1.1);
        }

        .love-letter h2 {
            color: #ff4444;
            text-align: center;
            margin-bottom: 20px;
            font-family: 'Arial', sans-serif;
        }

        .love-letter p {
            color: #333;
            line-height: 1.6;
            margin-bottom: 15px;
            font-family: 'Arial', sans-serif;
            text-align: justify;
        }

        .love-letter .signature {
            text-align: right;
            color: #ff4444;
            font-style: italic;
            margin-top: 20px;
        }

        .love-letter-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.5);
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
            z-index: 999;
        }

        .love-letter-overlay.active {
            opacity: 1;
            visibility: visible;
        }
    </style>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="loading">
        <div>加载中...</div>
        <div class="progress">
            <div class="progress-bar"></div>
        </div>
    </div>
    <div class="music-control" style="display: none;">
        <i class="fas fa-music"></i>
    </div>
    <!-- 添加情书弹窗 -->
    <div class="love-letter-overlay"></div>
    <div class="love-letter">
        <button class="close-btn">
            <i class="fas fa-times"></i>
        </button>
        <h2>亲爱的宝贝</h2>
        <p>在这个充满魔力的圣诞季节，我想对你说一些话...</p>
        <p>遇见你是我生命中最美好的礼物，你的笑容就像圣诞树顶的星星，照亮了我的整个世界。</p>
        <p>和你在一起的每一刻都是那么珍贵，就像圣诞树上闪烁的灯光，温暖而明亮。</p>
        <p>希望我们能一直这样手牵手走下去，共同创造更多美好的回忆。</p>
        <p>圣诞快乐，我的爱！</p>
        <div class="signature">永远爱你的我</div>
    </div>
    <!-- 添加相框查看器 -->
    <div class="photo-viewer">
        <button class="close-btn">
            <i class="fas fa-times"></i>
        </button>
        <button class="nav-btn prev-btn">
            <i class="fas fa-chevron-left"></i>
        </button>
        <img src="" alt="photo">
        <button class="nav-btn next-btn">
            <i class="fas fa-chevron-right"></i>
        </button>
    </div>
    <audio id="bgMusic" loop>
        <source src="https://cdn.jsdelivr.net/gh/microsoft/microsoft-3d-audio-toolkit@main/audio/jingle-bells.mp3" type="audio/mpeg">
    </audio>
    <script type="importmap">
    {
        "imports": {
            "three": "https://unpkg.com/three@0.158.0/build/three.module.js",
            "three/addons/": "https://unpkg.com/three@0.158.0/examples/jsm/"
        }
    }
    </script>
    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
        import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
        import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
        import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
        import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';

        let scene, camera, renderer, controls, composer;
        let christmasTree, lights = [];
        const ornaments = [];

        // 添加纹理加载器
        const textureLoader = new THREE.TextureLoader();
        
        // 预加载纹理
        const textures = {
            bark: null,
            needles: null,
            floor: null,
            snow: null
        };

        // 修改加载纹理的函数
        function loadTextures() {
            return new Promise((resolve, reject) => {
                let loadedCount = 0;
                const totalCount = 4; // 总共需要加载的纹理数量
                const progressBar = document.querySelector('.progress-bar');
                
                function updateProgress() {
                    loadedCount++;
                    const progress = (loadedCount / totalCount) * 100;
                    progressBar.style.width = `${progress}%`;
                }

                const loadingPromises = [
                    new Promise((res) => {
                        textures.bark = textureLoader.load(
                            'https://cdn.jsdelivr.net/gh/mrdoob/three.js/examples/textures/hardwood2_diffuse.jpg',
                            () => {
                                updateProgress();
                                res();
                            },
                            undefined,
                            () => {
                                console.warn('Failed to load bark texture');
                                textures.bark = new THREE.Texture();
                                updateProgress();
                                res();
                            }
                        );
                    }),
                    new Promise((res) => {
                        textures.needles = textureLoader.load(
                            'https://cdn.jsdelivr.net/gh/mrdoob/three.js/examples/textures/terrain/grasslight-big.jpg',
                            res,
                            undefined,
                            () => {
                                console.warn('Failed to load needles texture');
                                textures.needles = new THREE.Texture();
                                res();
                            }
                        );
                    }),
                    new Promise((res) => {
                        textures.floor = textureLoader.load(
                            'https://cdn.jsdelivr.net/gh/mrdoob/three.js/examples/textures/hardwood2_diffuse.jpg',
                            res,
                            undefined,
                            () => {
                                console.warn('Failed to load floor texture');
                                textures.floor = new THREE.Texture();
                                res();
                            }
                        );
                    }),
                    new Promise((res) => {
                        textures.snow = textureLoader.load(
                            '',
                            res,
                            undefined,
                            () => {
                                console.warn('Failed to load snow texture');
                                textures.snow = new THREE.Texture();
                                res();
                            }
                        );
                    })
                ];

                Promise.all(loadingPromises)
                    .then(() => {
                        Object.values(textures).forEach(texture => {
                            if (texture) {
                                texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
                                texture.repeat.set(4, 4);
                            }
                        });
                        resolve();
                    })
                    .catch(reject);
            });
        }

        // 初始化场景
        function init() {
            // 创建场景
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x0a1526); // 深蓝色背景

            // 优化相机设置 - 移到最前面
            camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
            camera.position.set(5, 2, 5); // 调整相机位置
            camera.lookAt(0, 1, 0); // 让相机看向圣诞树中部

            // 创建渲染器
            renderer = new THREE.WebGLRenderer({ 
                antialias: false,
                alpha: true,
                powerPreference: "high-performance",
                precision: "mediump"
            });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
            renderer.shadowMap.enabled = true;
            renderer.shadowMap.type = THREE.BasicShadowMap;
            renderer.outputEncoding = THREE.sRGBEncoding;
            renderer.toneMapping = THREE.ACESFilmicToneMapping;
            renderer.toneMappingExposure = 1.2;
            document.body.appendChild(renderer.domElement);

            // ���化轨道控制
            controls = new OrbitControls(camera, renderer.domElement);
            controls.enableDamping = true;
            controls.dampingFactor = 0.05;
            controls.minDistance = 3;
            controls.maxDistance = 8;
            controls.maxPolarAngle = Math.PI / 2.1;
            controls.minPolarAngle = Math.PI / 6;
            controls.target.set(0, 1, 0);

            // 创建月亮
            const moonGeometry = new THREE.CircleGeometry(3, 32);
            const moonMaterial = new THREE.MeshBasicMaterial({
                color: 0xfffae6,
                transparent: true,
                opacity: 1.0,
                side: THREE.DoubleSide
            });
            const moon = new THREE.Mesh(moonGeometry, moonMaterial);
            moon.position.set(-20, 25, -50);
            moon.lookAt(camera.position);
            scene.add(moon);

            // 创�����月亮光晕
            const moonGlowGeometry = new THREE.CircleGeometry(3.5, 32);
            const moonGlowMaterial = new THREE.MeshBasicMaterial({
                color: 0xfffae6,
                transparent: true,
                opacity: 0.2,
                side: THREE.DoubleSide
            });
            const moonGlow = new THREE.Mesh(moonGlowGeometry, moonGlowMaterial);
            moonGlow.position.copy(moon.position);
            moonGlow.lookAt(camera.position);
            scene.add(moonGlow);

            // 添加月光
            const moonLight = new THREE.DirectionalLight(0xfffae6, 0.8);
            moonLight.position.copy(moon.position);
            scene.add(moonLight);

            // 添加月亮动画
            moon.tick = function(time) {
                this.lookAt(camera.position);
                moonGlow.lookAt(camera.position);
            };
            scene.userData.animatedObjects = scene.userData.animatedObjects || [];
            scene.userData.animatedObjects.push(moon);

            // 创建更明显的星星
            const starsGeometry = new THREE.BufferGeometry();
            const starsVertices = [];
            const starColors = [];
            const starSizes = [];
            
            // 增加星星数量，减小大小
            for (let i = 0; i < 2000; i++) {
                const x = Math.random() * 200 - 100;
                const y = Math.random() * 100 + 10;
                const z = Math.random() * 200 - 100;
                const size = Math.random() * 0.5 + 0.5; // 减小星星的基础大小
                
                const distanceToMoon = Math.sqrt(
                    Math.pow(x - moon.position.x, 2) + 
                    Math.pow(y - moon.position.y, 2) + 
                    Math.pow(z - moon.position.z, 2)
                );
                
                if (distanceToMoon > 20) {
                    starsVertices.push(x, y, z);
                    // 调整星星的颜色
                    const color = new THREE.Color(0xffffff);
                    color.lerp(new THREE.Color(0xccccff), Math.random() * 0.05);
                    starColors.push(color.r, color.g, color.b);
                    starSizes.push(size);
                }
            }
            
            starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3));
            starsGeometry.setAttribute('color', new THREE.Float32BufferAttribute(starColors, 3));
            starsGeometry.setAttribute('size', new THREE.Float32BufferAttribute(starSizes, 1));
            
            const starsMaterial = new THREE.PointsMaterial({
                size: 0.5,
                transparent: true,
                opacity: 0.8,
                vertexColors: true,
                sizeAttenuation: true,
                blending: THREE.AdditiveBlending,
                depthWrite: false
            });
            
            const starField = new THREE.Points(starsGeometry, starsMaterial);
            scene.add(starField);

            // 添加星星闪烁动画
            starField.tick = function(time) {
                const sizes = this.geometry.attributes.size.array;
                for (let i = 0; i < sizes.length; i++) {
                    const originalSize = starSizes[i];
                    // 减小闪烁幅度
                    sizes[i] = originalSize * (0.8 + Math.sin(time * 2 + i) * 0.2);
                }
                this.geometry.attributes.size.needsUpdate = true;
            };

            // 将starField添加到需要更新的对象列表中
            scene.userData.animatedObjects = scene.userData.animatedObjects || [];
            scene.userData.animatedObjects.push(starField);

            // 调整雾效果
            scene.fog = new THREE.FogExp2(0x0a1526, 0.015);

            // 添加环境光
            const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
            scene.add(ambientLight);

            // 创建场景元素
            createFloor();
            createChristmasTree();
            createOrnaments();
            createLights();
            createPresents();
            createSnow();
            createPhotoFrames(); // 添加相框创建函数调用
            createSnowmen();
            createCouple();
            createSnowmanTraces();
            createSnowHeartPattern();
            createFloorDecorations();

            // 初始化后期处理
            initPostProcessing();

            // 开始动画循环
            animate();
        }

        // 创建礼物函数
        function createPresents() {
            // 定义更多礼物颜色
            const presentColors = [
                0x00aa44, // 绿色
                0xff0000, // 红色
                0xd4af37, // 金色
                0x4169e1, // 蓝色
                0xff69b4, // 粉色
                0x9932cc, // 紫色
                0xff8c00  // 橙色
            ];
            
            // 定义丝带颜色
            const ribbonColors = [
                0xff0000, // 红色
                0xffffff, // 白色
                0xffd700, // 金色
                0x00ff00  // 绿色
            ];

            // 礼物位置配置 - 增加更多礼物
            const presents = [
                // 最外面的红色礼物（放在最前面，确保容易点击）
                { size: [0.5, 0.35, 0.5], pos: [0, 0.175, -1.5], color: 0xff0000, ribbon: 0xffd700 },
                
                // 圣诞树前方的礼物
                { size: [0.4, 0.3, 0.4], pos: [-0.8, 0.15, -0.8], color: 0x00aa44, ribbon: 0xff0000 },
                { size: [0.45, 0.3, 0.45], pos: [0.8, 0.15, -0.8], color: 0x4169e1, ribbon: 0xffffff },
                { size: [0.4, 0.25, 0.4], pos: [-0.4, 0.125, -1.2], color: 0xd4af37, ribbon: 0xff0000 },
                { size: [0.35, 0.3, 0.35], pos: [0.4, 0.15, -1.2], color: 0xff69b4, ribbon: 0xffffff },
                
                // 圣诞树左侧的礼物堆
                { size: [0.3, 0.25, 0.3], pos: [-1.2, 0.125, -0.4], color: 0x9932cc, ribbon: 0xffd700 },
                { size: [0.35, 0.28, 0.35], pos: [-1.4, 0.14, -0.6], color: 0xff8c00, ribbon: 0x00ff00 },
                { size: [0.38, 0.32, 0.38], pos: [-1.1, 0.16, -0.7], color: 0x4169e1, ribbon: 0xffffff },
                
                // 圣诞树右侧的礼物堆
                { size: [0.36, 0.29, 0.36], pos: [1.3, 0.145, -0.5], color: 0x00aa44, ribbon: 0xff0000 },
                { size: [0.32, 0.26, 0.32], pos: [1.5, 0.13, -0.7], color: 0x00aa44, ribbon: 0xff0000 },
                { size: [0.34, 0.27, 0.34], pos: [1.2, 0.135, -0.8], color: 0xff69b4, ribbon: 0xffffff },
                
                // 后排的礼物
                { size: [0.55, 0.4, 0.55], pos: [-0.6, 0.2, -1.4], color: 0xd4af37, ribbon: 0xff0000 },
                { size: [0.5, 0.38, 0.5], pos: [0.6, 0.19, -1.5], color: 0x4169e1, ribbon: 0xffd700 }
            ];

            presents.forEach(present => {
                // 创建礼物盒
                const boxGeometry = new THREE.BoxGeometry(...present.size);
                const boxMaterial = new THREE.MeshStandardMaterial({
                    color: present.color,
                    metalness: 0.1,
                    roughness: 0.8,
                    envMapIntensity: 0.5
                });
                
                const box = new THREE.Mesh(boxGeometry, boxMaterial);
                box.position.set(...present.pos);
                box.castShadow = true;
                box.receiveShadow = true;
                box.rotation.y = Math.random() * Math.PI * 0.2 - Math.PI * 0.1;
                
                // 如果是红色礼物，添加用户数据标记
                if (present.color === 0xff0000) {
                    box.userData.isRedGift = true;
                }
                
                scene.add(box);

                // 创建丝带
                const ribbonMaterial = new THREE.MeshStandardMaterial({
                    color: present.ribbon,
                    metalness: 0.1,
                    roughness: 0.8,
                    envMapIntensity: 0.5
                });

                // 水平丝带
                const ribbonWidth = present.size[0] * 0.15;
                const horizontalRibbon = new THREE.Mesh(
                    new THREE.BoxGeometry(present.size[0], ribbonWidth, present.size[2]),
                    ribbonMaterial
                );
                horizontalRibbon.position.set(
                    present.pos[0],
                    present.pos[1] + present.size[1]/2,
                    present.pos[2]
                );
                horizontalRibbon.rotation.y = box.rotation.y;
                horizontalRibbon.castShadow = true;
                scene.add(horizontalRibbon);

                // 垂直丝带
                const verticalRibbon = new THREE.Mesh(
                    new THREE.BoxGeometry(ribbonWidth, present.size[1], present.size[2]),
                    ribbonMaterial
                );
                verticalRibbon.position.set(
                    present.pos[0],
                    present.pos[1],
                    present.pos[2]
                );
                verticalRibbon.rotation.y = box.rotation.y;
                verticalRibbon.castShadow = true;
                scene.add(verticalRibbon);

                // 创建更精美的蝴蝶结
                const bowSize = present.size[0] * 0.35;
                const bowHeight = ribbonWidth * 1.8;
                
                // 创建蝴蝶结的中心部分
                const bowCenter = new THREE.Mesh(
                    new THREE.BoxGeometry(ribbonWidth * 1.4, bowHeight * 0.6, ribbonWidth * 1.4),
                    ribbonMaterial
                );
                bowCenter.position.set(
                    present.pos[0],
                    present.pos[1] + present.size[1] + bowHeight/3,
                    present.pos[2]
                );
                bowCenter.rotation.y = box.rotation.y;
                bowCenter.castShadow = true;
                scene.add(bowCenter);

                // 创建蝴蝶结的翅膀
                const createBowWing = (angleX, angleZ, posX) => {
                    const wing = new THREE.Mesh(
                        new THREE.BoxGeometry(bowSize * 0.7, bowHeight * 0.5, ribbonWidth),
                        ribbonMaterial
                    );
                    wing.position.set(
                        present.pos[0] + posX,
                        present.pos[1] + present.size[1] + bowHeight/3,
                        present.pos[2]
                    );
                    wing.rotation.set(angleX, box.rotation.y, angleZ);
                    wing.castShadow = true;
                    scene.add(wing);
                };

                // 创建四个翅膀
                createBowWing(0.3, 0.4, bowSize * 0.3);
                createBowWing(0.3, -0.4, -bowSize * 0.3);
                createBowWing(-0.3, 0.4, bowSize * 0.3);
                createBowWing(-0.3, -0.4, -bowSize * 0.3);

                // 创建蝴蝶结的装饰带
                const createRibbonTail = (posX, rotZ) => {
                    const tail = new THREE.Mesh(
                        new THREE.BoxGeometry(ribbonWidth, bowHeight * 1.2, ribbonWidth/4),
                        ribbonMaterial
                    );
                    tail.position.set(
                        present.pos[0] + posX,
                        present.pos[1] + present.size[1] - bowHeight/3,
                        present.pos[2]
                    );
                    tail.rotation.set(0, box.rotation.y, rotZ);
                    tail.castShadow = true;
                    scene.add(tail);

                    // 添加波浪效果
                    const wave = new THREE.Mesh(
                        new THREE.BoxGeometry(ribbonWidth * 0.8, bowHeight * 0.4, ribbonWidth/4),
                        ribbonMaterial
                    );
                    wave.position.set(
                        present.pos[0] + posX * 1.2,
                        present.pos[1] + present.size[1] - bowHeight/2,
                        present.pos[2]
                    );
                    wave.rotation.set(0, box.rotation.y, rotZ * 1.5);
                    wave.castShadow = true;
                    scene.add(wave);
                };

                // 创建装饰带
                createRibbonTail(ribbonWidth * 1.2, Math.PI/6);
                createRibbonTail(-ribbonWidth * 1.2, -Math.PI/6);

                // 添加装饰亮点
                const highlight = new THREE.Mesh(
                    new THREE.SphereGeometry(ribbonWidth * 0.3, 8, 8),
                    new THREE.MeshPhysicalMaterial({
                        color: 0xffffff,
                        metalness: 0.3,    // 降低金属度
                        roughness: 0.4,    // 增加粗糙度
                        clearcoat: 0.3,    // 降低清漆效果
                        clearcoatRoughness: 0.6  // 增加清漆的粗糙度
                    })
                );
                highlight.position.set(
                    present.pos[0],
                    present.pos[1] + present.size[1] + bowHeight/3,
                    present.pos[2]
                );
                highlight.castShadow = true;
                scene.add(highlight);
            });

            // 添加点击事件处理
            const raycaster = new THREE.Raycaster();
            const mouse = new THREE.Vector2();

            // 添加点击事件监听器
            renderer.domElement.addEventListener('click', (event) => {
                mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
                mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;

                raycaster.setFromCamera(mouse, camera);
                const intersects = raycaster.intersectObjects(scene.children);

                for (let i = 0; i < intersects.length; i++) {
                    const object = intersects[i].object;
                    if (object.userData.isRedGift) {
                        showLoveLetter();
                        break;
                    }
                }
            });
        }

        // 添加显示情书的函数
        function showLoveLetter() {
            const letter = document.querySelector('.love-letter');
            const overlay = document.querySelector('.love-letter-overlay');
            letter.classList.add('active');
            overlay.classList.add('active');

            // 添加关闭事件
            const closeBtn = letter.querySelector('.close-btn');
            const closeLetter = () => {
                letter.classList.remove('active');
                overlay.classList.remove('active');
            };

            closeBtn.addEventListener('click', closeLetter);
            overlay.addEventListener('click', closeLetter);
        }

        // 创建雪花
        function createSnow() {
            const snowCount = 100; // 减少雪花数量
            const geometry = new THREE.BufferGeometry();
            const vertices = [];

            for (let i = 0; i < snowCount; i++) {
                vertices.push(
                    Math.random() * 20 - 10,
                    Math.random() * 20,
                    Math.random() * 20 - 10
                );
            }

            geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));

            const snowTexture = new THREE.TextureLoader().load(
                '',
            );

            const material = new THREE.PointsMaterial({
                size: 0.15,
                map: snowTexture,
                transparent: true,
                opacity: 0.6,
                depthWrite: false,
                blending: THREE.AdditiveBlending
            });

            const snow = new THREE.Points(geometry, material);
            scene.add(snow);

            snow.tick = function(time) {
                const positions = this.geometry.attributes.position.array;
                for (let i = 0; i < positions.length; i += 3) {
                    positions[i + 1] -= 0.03;
                    positions[i] += Math.sin(time + i) * 0.005;
                    if (positions[i + 1] < 0) {
                        positions[i + 1] = 20;
                        positions[i] = Math.random() * 20 - 10;
                        positions[i + 2] = Math.random() * 20 - 10;
                    }
                }
                this.geometry.attributes.position.needsUpdate = true;
            };

            scene.userData.animatedObjects = scene.userData.animatedObjects || [];
            scene.userData.animatedObjects.push(snow);

            return snow;
        }

        // 创建圣诞树
        function createChristmasTree() {
            const segments = 10;  // 增加层
            const treeHeight = 3.5;  // 圣诞树的总高度

            // 修改树干高度
            const trunkHeight = 0.6;
            const trunkRadiusTop = 0.15;
            const trunkRadiusBottom = 0.25;

            // 主树干
            const trunkGeometry = new THREE.CylinderGeometry(
                trunkRadiusTop, 
                trunkRadiusBottom, 
                trunkHeight, 
                12,  // 分段数
                4,   // 高度分段
                true // 开放端
            );

            const trunkMaterial = new THREE.MeshStandardMaterial({
                color: 0x4a2f1b,  // 更深的棕色
                map: textures.bark,
                normalMap: textures.bark,
                roughnessMap: textures.bark,
                roughness: 0.9,
                metalness: 0.1,
                bumpMap: textures.bark,
                bumpScale: 0.5,
                premultipliedAlpha: true,
                precision: "mediump"
            });

            const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
            trunk.position.y = trunkHeight / 2;
            trunk.castShadow = true;
            scene.add(trunk);

            // 添加树根部分
            const rootGeometry = new THREE.CylinderGeometry(
                trunkRadiusBottom * 1.5, 
                trunkRadiusBottom * 0.8, 
                trunkHeight * 0.3, 
                8
            );

            const root = new THREE.Mesh(rootGeometry, trunkMaterial);
            root.position.y = 0.15;
            root.castShadow = true;
            scene.add(root);

            // 添加树干节点
            for (let i = 0; i < 4; i++) {
                const knot = new THREE.Mesh(
                    new THREE.SphereGeometry(trunkRadiusTop * 0.8, 8, 8),
                    trunkMaterial
                );
                
                const height = trunkHeight * (0.2 + i * 0.25);
                const angle = i * Math.PI * 0.5;
                const radius = trunkRadiusTop * 0.7;
                
                knot.position.set(
                    Math.cos(angle) * radius,
                    height,
                    Math.sin(angle) * radius
                );
                knot.scale.set(1.2, 0.8, 1.2);
                knot.castShadow = true;
                scene.add(knot);
            }

            // 修改树叶层的建
            for (let i = 0; i < segments; i++) {
                const radius = 1.4 * (1 - (i / segments) * 0.8);  // 调整半变化率
                const height = 0.25;  // 减小每层高度使层次更密集
                const yPosition = trunkHeight + i * 0.2;  // 减小层间距

                // 为每层创建多个重叠的锥体，制造层次感
                for (let layer = 0; layer < 4; layer++) {  // 增加重叠层数
                    const layerRadius = radius * (1 - layer * 0.1);
                    const layerHeight = height * (1 + layer * 0.15);
                    const coneGeometry = new THREE.ConeGeometry(layerRadius, layerHeight, 32, 16, true);
                    const coneMaterial = new THREE.MeshStandardMaterial({
                        color: new THREE.Color(
                            0.1 + Math.random() * 0.05,
                            0.35 + Math.random() * 0.1,
                            0.1 + Math.random() * 0.05
                        ),
                        map: textures.needles,
                        normalMap: textures.needles,
                        roughnessMap: textures.needles,
                        roughness: 0.8,
                        metalness: 0.2,
                        side: THREE.DoubleSide,
                        transparent: true,
                        alphaTest: 0.5
                    });

                    const cone = new THREE.Mesh(coneGeometry, coneMaterial);
                    cone.position.y = yPosition + layer * 0.03;
                    cone.rotation.y = Math.random() * Math.PI * 2;
                    cone.rotation.z = (Math.random() - 0.5) * 0.1;
                    cone.castShadow = true;
                    scene.add(cone);
                }

                // 增加针叶细节
                const needlesCount = 100;  // 增加针叶数量
                for (let j = 0; j < needlesCount; j++) {
                    const needleGeometry = new THREE.CylinderGeometry(0.002, 0.001, 0.08, 3);
                    const needleMaterial = new THREE.MeshStandardMaterial({
                        color: new THREE.Color(
                            0.1 + Math.random() * 0.1,
                            0.3 + Math.random() * 0.2,
                            0.1 + Math.random() * 0.1
                        ),
                        roughness: 0.7
                    });

                    const needle = new THREE.Mesh(needleGeometry, needleMaterial);
                    const theta = Math.random() * Math.PI * 2;
                    const r = Math.random() * radius;
                    
                    needle.position.set(
                        Math.cos(theta) * r,
                        yPosition + Math.random() * height,
                        Math.sin(theta) * r
                    );
                    
                    needle.rotation.x = (Math.random() - 0.5) * Math.PI * 0.5;
                    needle.rotation.y = Math.random() * Math.PI * 2;
                    needle.rotation.z = (Math.random() - 0.5) * Math.PI * 0.5;
                    
                    needle.castShadow = true;
                    scene.add(needle);
                }

                // 添加小树枝
                const branchesCount = 24;  // 增加树枝数量
                for (let j = 0; j < branchesCount; j++) {
                    const branchGeometry = new THREE.CylinderGeometry(0.01, 0.005, radius * 0.8, 3);
                    const branchMaterial = new THREE.MeshStandardMaterial({
                        color: 0x3d2817,
                        roughness: 0.9
                    });
                    
                    const branch = new THREE.Mesh(branchGeometry, branchMaterial);
                    const theta = (j / branchesCount) * Math.PI * 2;
                    const r = radius * 0.7;
                    
                    branch.position.set(
                        Math.cos(theta) * r,
                        yPosition,
                        Math.sin(theta) * r
                    );
                    
                    branch.rotation.z = Math.PI * 0.3;
                    branch.rotation.y = theta;
                    branch.castShadow = true;
                    scene.add(branch);

                    // 为每个枝添加更多针叶
                    for (let k = 0; k < 12; k++) {
                        const needleGeometry = new THREE.CylinderGeometry(0.002, 0.001, 0.1, 3);
                        const needleMaterial = new THREE.MeshStandardMaterial({
                            color: new THREE.Color(
                                0.1 + Math.random() * 0.1,
                                0.3 + Math.random() * 0.2,
                                0.1 + Math.random() * 0.1
                            ),
                            roughness: 0.7
                        });
                        
                        const needle = new THREE.Mesh(needleGeometry, needleMaterial);
                        needle.position.copy(branch.position);
                        needle.position.y += Math.random() * 0.1 - 0.05;
                        needle.rotation.set(
                            Math.random() * Math.PI,
                            Math.random() * Math.PI,
                            Math.random() * Math.PI
                        );
                        needle.castShadow = true;
                        scene.add(needle);
                    }
                }
            }

            // 修改爱心的创建和位置
            const heartShape = new THREE.Shape();
            const x = 0, y = 0;
            const heartWidth = 0.25;
            const heartHeight = 0.25;

            // 绘制更标准的爱心形状
            heartShape.moveTo(x, y);

            // 左半边
            heartShape.bezierCurveTo(
                x, y + heartHeight * 0.3,           // 控制点1
                x - heartWidth * 0.5, y + heartHeight * 0.3,  // 控制点2
                x - heartWidth * 0.5, y + heartHeight * 0.6   // 终点
            );
            heartShape.bezierCurveTo(
                x - heartWidth * 0.5, y + heartHeight * 0.9,  // 控制点1
                x - heartWidth * 0.3, y + heartHeight,        // 控制点2
                x, y + heartHeight * 0.7                      // 终点
            );

            // 右半边（对称）
            heartShape.bezierCurveTo(
                x + heartWidth * 0.3, y + heartHeight,        // 控制点1
                x + heartWidth * 0.5, y + heartHeight * 0.9,  // 控制点2
                x + heartWidth * 0.5, y + heartHeight * 0.6   // 终点
            );
            heartShape.bezierCurveTo(
                x + heartWidth * 0.5, y + heartHeight * 0.3,  // 控制点1
                x, y + heartHeight * 0.3,                     // 控制点2
                x, y                                          // 终点
            );

            // 调整挤出参数
            const heartGeometry = new THREE.ExtrudeGeometry(heartShape, {
                depth: 0.15,
                bevelEnabled: true,
                bevelThickness: 0.08,
                bevelSize: 0.03,
                bevelOffset: 0,
                bevelSegments: 8
            });

            // 调整材质
            const heartMaterial = new THREE.MeshPhysicalMaterial({
                color: 0xff0000,       // 更鲜艳的红色
                metalness: 0.4,
                roughness: 0.2,
                emissive: 0xff0000,    // 添加发光效果
                emissiveIntensity: 0.5, // 增加发光度
                clearcoat: 1.0,        // 添加清漆效果
                clearcoatRoughness: 0.1
            });

            const heart = new THREE.Mesh(heartGeometry, heartMaterial);
            
            // 调整位置，确保在树顶上方
            heart.position.set(0, treeHeight + 0.3, 0);  // 放在树顶上方
            heart.scale.set(0.8, 0.8, 0.8);  // 调整大小

            // 修改爱心动画
            heart.tick = function(time) {
                // 使爱心始终面向相机
                this.lookAt(camera.position);
                // 添加额外的旋转来调整朝向
                this.rotateY(Math.PI);
                
                // 上下浮动
                this.position.y = treeHeight + 0.3 + Math.sin(time * 1.5) * 0.1;
                // 轻微放
                const scale = 0.8 + Math.sin(time * 2) * 0.05;
                this.scale.set(scale, scale, scale);
            };

            heart.castShadow = true;
            scene.add(heart);
            
            // 将爱心添加到需要更新的对象列表中
            scene.userData.animatedObjects = scene.userData.animatedObjects || [];
            scene.userData.animatedObjects.push(heart);
        }

        // 创建装饰球
        function createOrnaments() {
            const colors = [
                0xff0000, // 红色
                0xffffff, // 白色
                0x00ff00, // 绿色
                0xffd700, // 金色
                0xff69b4, // 粉色
                0x4169e1  // 蓝色
            ];
            
            // 增加装饰球数量
            for (let i = 0; i < 30; i++) {
                const radius = 0.06 + Math.random() * 0.02;
                const geometry = new THREE.SphereGeometry(radius, 32, 32);
                const material = new THREE.MeshPhysicalMaterial({
                    color: colors[Math.floor(Math.random() * colors.length)],
                    metalness: 0.8,
                    roughness: 0.2,
                    clearcoat: 0.5,
                    clearcoatRoughness: 0.1,
                    reflectivity: 1.0,
                    envMapIntensity: 1.0
                });
                const ornament = new THREE.Mesh(geometry, material);

                // 随机位置
                const theta = Math.random() * Math.PI * 2;
                const radius_pos = Math.random() * 1.2;
                const height = Math.random() * 3 + 0.5;
                
                ornament.position.x = Math.cos(theta) * radius_pos;
                ornament.position.y = height;
                ornament.position.z = Math.sin(theta) * radius_pos;
                
                // 添加装饰球动画
                ornament.userData.originalPosition = {
                    x: ornament.position.x,
                    y: ornament.position.y,
                    z: ornament.position.z
                };
                ornament.userData.rotationSpeed = Math.random() * 2;
                ornament.userData.floatSpeed = 0.5 + Math.random();
                ornament.userData.floatAmplitude = 0.05 + Math.random() * 0.05;
                
                ornament.castShadow = true;
                scene.add(ornament);
                ornaments.push(ornament);

                // 添加装饰球吊绳
                const ropeGeometry = new THREE.CylinderGeometry(0.002, 0.002, height * 0.2, 3);
                const ropeMaterial = new THREE.MeshStandardMaterial({
                    color: 0xc0c0c0,
                    metalness: 0.8,
                    roughness: 0.2
                });
                const rope = new THREE.Mesh(ropeGeometry, ropeMaterial);
                rope.position.set(
                    ornament.position.x,
                    ornament.position.y + height * 0.1,
                    ornament.position.z
                );
                scene.add(rope);
            }
        }

        // 创建灯串
        function createLights() {
            const lightCount = 15; // 减少灯泡数量
            const lightGroup = new THREE.Group();
            const colors = [0xff0000, 0x00ff00, 0xffd700, 0xff69b4, 0x4169e1];
            
            // 创建一个享灯泡几何体和材质
            const bulbGeometry = new THREE.SphereGeometry(0.04, 8, 8); // 减少细分
            const bulbMaterials = colors.map(color => new THREE.MeshPhysicalMaterial({
                color: color,
                transparent: true,
                opacity: 0.7,
                metalness: 0.2,
                roughness: 0.1,
                clearcoat: 1.0,
                clearcoatRoughness: 0.1
            }));

            for (let i = 0; i < lightCount; i++) {
                const bulb = new THREE.Mesh(
                    bulbGeometry,
                    bulbMaterials[i % colors.length]
                );

                // 创建发光点光源（减少光源数量，每两个灯泡共用一个光源）
                if (i % 2 === 0) {
                    const light = new THREE.PointLight(colors[i % colors.length], 0.3, 0.5);
                    light.intensity = 0.3;
                    light.userData.originalIntensity = light.intensity;
                    light.userData.flickerSpeed = 2 + Math.random() * 2;
                    lights.push(light);
                    lightGroup.add(light);
                }
                
                const theta = (i / lightCount) * Math.PI * 8;
                const radius = 0.8 - (i / lightCount) * 0.3;
                const height = (i / lightCount) * 3 + 0.5;

                bulb.position.set(
                    Math.cos(theta) * radius,
                    height,
                    Math.sin(theta) * radius
                );

                // 果创建了光源，将其位置设置为当前灯泡位置
                if (i % 2 === 0) {
                    lights[lights.length - 1].position.copy(bulb.position);
                }
                
                lightGroup.add(bulb);
            }
            
            scene.add(lightGroup);
        }

        // 在动画循环中更新装饰物动画
        function updateDecorations(time) {
            // 更新装饰球动画
            ornaments.forEach(ornament => {
                const originalPos = ornament.userData.originalPosition;
                
                // 旋转动画
                ornament.rotation.x = time * ornament.userData.rotationSpeed;
                ornament.rotation.y = time * ornament.userData.rotationSpeed * 0.7;
                
                // 漂浮动画
                ornament.position.y = originalPos.y + 
                    Math.sin(time * ornament.userData.floatSpeed) * 
                    ornament.userData.floatAmplitude;
                
                // 轻微摆动
                const swayAmount = 0.02;
                ornament.position.x = originalPos.x + Math.sin(time * 2) * swayAmount;
                ornament.position.z = originalPos.z + Math.cos(time * 2) * swayAmount;
            });

            // 更新灯光动画
            lights.forEach(light => {
                // 闪烁效果
                light.intensity = light.userData.originalIntensity * 
                    (0.8 + Math.sin(time * light.userData.flickerSpeed) * 0.2);
            });

            // 更新爱心动画
            scene.userData.animatedObjects?.forEach(obj => {
                if (obj.tick) {
                    obj.tick(time);
                }
            });
        }

        // 在主动画循环中调用装饰物更新
        function animate() {
            requestAnimationFrame(animate);
            if (!renderer || !scene || !camera || !controls) return;
            
            const time = Date.now() * 0.001;

            // 限制更新频率
            if (time - lastUpdateTime > 0.016) {
                updateDecorations(time);
                
                // 添加相机轻微摇摆
                if (!controls.enabled) { // 只在用户不操作时添加摇摆
                    camera.position.y += Math.sin(time * 0.5) * 0.001;
                    camera.position.x += Math.sin(time * 0.3) * 0.001;
                }
                
                lastUpdateTime = time;
            }

            controls.update();

            if (composer && composer.renderer) {
                composer.render();
            } else {
                renderer.render(scene, camera);
            }
        }

        let lastUpdateTime = 0;

        // 初始化后期处理
        function initPostProcessing() {
            try {
                composer = new EffectComposer(renderer);
                const renderPass = new RenderPass(scene, camera);
                composer.addPass(renderPass);

                const bloomPass = new UnrealBloomPass(
                    new THREE.Vector2(window.innerWidth / 2, window.innerHeight / 2), // 降低分辨率
                    1.0,  // 降低强度
                    0.4,
                    0.85
                );
                composer.addPass(bloomPass);
            } catch (error) {
                console.error('Error initializing post-processing:', error);
                composer = null;
            }
        }

        // 窗口大小调整
        function onWindowResize() {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.setPixelRatio(window.devicePixelRatio);
        }

        window.addEventListener('resize', onWindowResize, false);

        // 修改地板创建函数，增强雪地效果
        function createFloor() {
            // 创建更大更细腻的板
            const floorGeometry = new THREE.PlaneGeometry(30, 30, 250, 250); // 增加地板大小和细节
            
            // 建更真实雪地材质
            const snowFloorMaterial = new THREE.MeshPhysicalMaterial({
                color: 0xffffff,
                metalness: 0.1,
                roughness: 0.8,
                clearcoat: 0.3,
                clearcoatRoughness: 0.4,
                reflectivity: 0.2,
                side: THREE.DoubleSide
            });

            const floor = new THREE.Mesh(floorGeometry, snowFloorMaterial);
            floor.rotation.x = -Math.PI / 2;
            floor.receiveShadow = true;
            
            // 创建更自然的雪地起伏
            const vertices = floor.geometry.attributes.position.array;
            for (let i = 0; i < vertices.length; i += 3) {
                const x = vertices[i];
                const z = vertices[i + 2];
                // 使用柏林噪声创建更自然的起伏
                vertices[i + 2] = (Math.sin(x * 0.5) * Math.cos(z * 0.5) * 0.2 +
                    Math.random() * 0.1) * (1 - Math.min(1, Math.sqrt(x * x + z * z) / 8));
            }
            floor.geometry.attributes.position.needsUpdate = true;
            floor.geometry.computeVertexNormals();
            scene.add(floor);

            // 添加雪地纹理细节
            const snowDetailCount = 800; // 增加雪地细节
            for (let i = 0; i < snowDetailCount; i++) {
                const detail = new THREE.Mesh(
                    new THREE.CircleGeometry(0.05 + Math.random() * 0.1, 4),
                    new THREE.MeshStandardMaterial({
                        color: 0xfafafa,
                        transparent: true,
                        opacity: 0.3 + Math.random() * 0.3
                    })
                );

                const radius = Math.random() * 8;
                const angle = Math.random() * Math.PI * 2;
                detail.position.set(
                    Math.cos(angle) * radius,
                    0.01,
                    Math.sin(angle) * radius
                );
                detail.rotation.x = -Math.PI / 2;
                detail.rotation.z = Math.random() * Math.PI;
                scene.add(detail);
            }

            // 添加雪堆效果
            const snowPileCount = 30;
            for (let i = 0; i < snowPileCount; i++) {
                const pile = new THREE.Mesh(
                    new THREE.SphereGeometry(0.2 + Math.random() * 0.3, 8, 6, 0, Math.PI * 2, 0, Math.PI / 2),
                    new THREE.MeshStandardMaterial({
                        color: 0xffffff,
                        roughness: 0.8,
                        metalness: 0.1
                    })
                );

                const radius = Math.random() * 7;
                const angle = Math.random() * Math.PI * 2;
                pile.position.set(
                    Math.cos(angle) * radius,
                    0,
                    Math.sin(angle) * radius
                );
                pile.rotation.y = Math.random() * Math.PI;
                scene.add(pile);
            }

            // 添加闪光效果
            const sparkleCount = 100;
            for (let i = 0; i < sparkleCount; i++) {
                const sparkle = new THREE.Mesh(
                    new THREE.PlaneGeometry(0.03, 0.03),
                    new THREE.MeshBasicMaterial({
                        color: 0xffffff,
                        transparent: true,
                        opacity: 0.4 + Math.random() * 0.3,
                        side: THREE.DoubleSide
                    })
                );

                const radius = Math.random() * 9;
                const angle = Math.random() * Math.PI * 2;
                sparkle.position.set(
                    Math.cos(angle) * radius,
                    0.02,
                    Math.sin(angle) * radius
                );
                sparkle.rotation.x = -Math.PI / 2;

                // 添加闪烁动画
                sparkle.userData.sparkle = true;
                sparkle.userData.speed = 0.5 + Math.random() * 2;
                scene.add(sparkle);
            }

            // 添加环境光晕
            const glowGeometry = new THREE.CircleGeometry(10, 32);
            const glowMaterial = new THREE.MeshBasicMaterial({
                color: 0xaaaaff,
                transparent: true,
                opacity: 0.1,
                side: THREE.DoubleSide
            });

            const glow = new THREE.Mesh(glowGeometry, glowMaterial);
            glow.position.y = 0.01;
            glow.rotation.x = -Math.PI / 2;
            scene.add(glow);

            // 在动画循环中添加闪光效果更新
            scene.userData.updateSparkles = function(time) {
                scene.children.forEach(child => {
                    if (child.userData.sparkle) {
                        child.material.opacity = 
                            (0.4 + Math.random() * 0.3) * 
                            (0.5 + Math.sin(time * child.userData.speed) * 0.5);
                    }
                });
            };
        }

        // 添加建雪人的函数
        function createSnowmen() {
            // 创建多个雪人
            const snowmenPositions = [
                { x: -3, z: -3, rotation: 0.8 },
                { x: 3, z: -2.5, rotation: -0.6 },
                { x: -2, z: -4, rotation: 0.3 }
            ];

            snowmenPositions.forEach(pos => {
                createSnowman(pos.x, pos.z, pos.rotation);
            });
        }

        function createSnowman(x, z, rotation) {
            const snowmanGroup = new THREE.Group();

            // 底部大雪球
            const bottomBall = new THREE.Mesh(
                new THREE.SphereGeometry(0.4, 32, 32),
                new THREE.MeshPhysicalMaterial({
                    color: 0xffffff,
                    roughness: 0.8,
                    metalness: 0.1,
                    clearcoat: 0.3
                })
            );
            bottomBall.position.y = 0.4;
            bottomBall.castShadow = true;
            snowmanGroup.add(bottomBall);

            // 中间雪球
            const middleBall = new THREE.Mesh(
                new THREE.SphereGeometry(0.3, 32, 32),
                new THREE.MeshPhysicalMaterial({
                    color: 0xffffff,
                    roughness: 0.8,
                    metalness: 0.1,
                    clearcoat: 0.3
                })
            );
            middleBall.position.y = 1;
            middleBall.castShadow = true;
            snowmanGroup.add(middleBall);

            // 头部小球
            const headBall = new THREE.Mesh(
                new THREE.SphereGeometry(0.2, 32, 32),
                new THREE.MeshPhysicalMaterial({
                    color: 0xffffff,
                    roughness: 0.8,
                    metalness: 0.1,
                    clearcoat: 0.3
                })
            );
            headBall.position.y = 1.45;
            headBall.castShadow = true;
            snowmanGroup.add(headBall);

            // 添加胡萝卜鼻子
            const nose = new THREE.Mesh(
                new THREE.ConeGeometry(0.04, 0.2, 32),
                new THREE.MeshStandardMaterial({ color: 0xff6600 })
            );
            nose.position.set(0, 1.45, 0.2);
            nose.rotation.x = Math.PI / 2;
            nose.castShadow = true;
            snowmanGroup.add(nose);

            // 添加眼睛
            const eyeGeometry = new THREE.SphereGeometry(0.02, 16, 16);
            const eyeMaterial = new THREE.MeshStandardMaterial({ color: 0x000000 });
            
            const leftEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
            leftEye.position.set(-0.08, 1.5, 0.15);
            snowmanGroup.add(leftEye);
            
            const rightEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
            rightEye.position.set(0.08, 1.5, 0.15);
            snowmanGroup.add(rightEye);

            // 添加纽扣
            const buttonGeometry = new THREE.SphereGeometry(0.02, 16, 16);
            const buttonMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });
            
            for (let i = 0; i < 3; i++) {
                const button = new THREE.Mesh(buttonGeometry, buttonMaterial);
                button.position.set(0, 1.1 - i * 0.15, 0.28);
                snowmanGroup.add(button);
            }

            // 添加围巾
            const scarfGeometry = new THREE.TorusGeometry(0.12, 0.04, 16, 32);
            const scarfMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
            const scarf = new THREE.Mesh(scarfGeometry, scarfMaterial);
            scarf.position.set(0, 1.25, 0);
            scarf.rotation.x = Math.PI / 2;
            snowmanGroup.add(scarf);

            // 围巾垂下的部分
            const scarfEnd = new THREE.Mesh(
                new THREE.BoxGeometry(0.08, 0.3, 0.04),
                scarfMaterial
            );
            scarfEnd.position.set(0.1, 1.15, 0);
            scarfEnd.rotation.z = Math.PI / 6;
            snowmanGroup.add(scarfEnd);

            // 添加树枝手臂
            const armGeometry = new THREE.CylinderGeometry(0.02, 0.01, 0.5, 8);
            const armMaterial = new THREE.MeshStandardMaterial({ color: 0x4a2f1b });
            
            const leftArm = new THREE.Mesh(armGeometry, armMaterial);
            leftArm.position.set(-0.4, 1.1, 0);
            leftArm.rotation.z = Math.PI / 4;
            snowmanGroup.add(leftArm);
            
            const rightArm = new THREE.Mesh(armGeometry, armMaterial);
            rightArm.position.set(0.4, 1.1, 0);
            rightArm.rotation.z = -Math.PI / 4;
            snowmanGroup.add(rightArm);

            // 设置雪人位置和旋转
            snowmanGroup.position.set(x, 0, z);
            snowmanGroup.rotation.y = rotation;

            // 添加简单的动画
            snowmanGroup.tick = function(time) {
                // 整体轻微摆动
                this.rotation.y = rotation + Math.sin(time * 0.5) * 0.05;
                
                // 手臂摆动
                rightArm.rotation.z = -Math.PI / 4 + Math.sin(time * 2) * 0.2;
                leftArm.rotation.z = Math.PI / 4 + Math.sin(time * 2 + Math.PI) * 0.2;
                
                // 身轻微晃动
                this.position.y = Math.sin(time * 1.5) * 0.02;
                
                // 围巾飘动
                scarfEnd.rotation.z = Math.PI / 6 + Math.sin(time * 3) * 0.1;
                
                // 头部轻微转动
                headBall.rotation.y = Math.sin(time * 0.8) * 0.1;
                
                // 鼻子轻微上下动
                nose.position.z = 0.2 + Math.sin(time * 2) * 0.01;
            };

            scene.add(snowmanGroup);
        }

        // 添加建情侣的函数
        function createCouple() {
            // 创建第一个人物（男生）
            const person1 = createPerson({
                position: { x: -2.5, y: 0, z: -2.5 },
                rotation: 0.4,
                color: 0x2244aa,  // 蓝色外套
                scarf: 0xff4444,  // 红色围巾
                hatColor: 0x333333 // 深灰色帽子
            });

            // 创建第二个人物（女生）
            const person2 = createPerson({
                position: { x: -1.8, y: 0, z: -1.8 }, // 调整到更远的位置
                rotation: -0.4,  // 调整旋转角度
                color: 0xff6699,  // 粉色外套
                scarf: 0xffffff,  // 白色围巾
                hatColor: 0xff6699 // 粉色帽子
            });

            // 优化动画效果
            person1.tick = function(time) {
                const head = this.userData.head;
                const leftArm = this.userData.leftArm;
                const rightArm = this.userData.rightArm;
                const scarf = this.userData.scarf;
                const leftLeg = this.userData.leftLeg;
                const rightLeg = this.userData.rightLeg;
                const leftGlove = this.userData.leftGlove;
                const rightGlove = this.userData.rightGlove;
                const hat = this.userData.hat;

                // 身体摆动
                this.rotation.x = Math.sin(time * 0.5) * 0.1;
                
                // 头部动作
                head.rotation.y = Math.sin(time * 0.8) * 0.2;
                head.rotation.z = Math.sin(time * 0.5) * 0.05;
                
                // 手臂动作
                leftArm.rotation.z = Math.PI / 4 + Math.sin(time * 2) * 0.2;
                rightArm.rotation.z = -Math.PI / 4 + Math.sin(time * 2 + Math.PI) * 0.2;
                
                // 手套跟随手臂
                leftGlove.position.y = 0.5 + Math.sin(time * 2) * 0.1;
                rightGlove.position.y = 0.5 + Math.sin(time * 2 + Math.PI) * 0.1;
                
                // 围巾飘动
                scarf.rotation.z = Math.sin(time * 3) * 0.1;
                
                // 帽子轻微摆动
                hat.rotation.z = Math.sin(time * 0.5) * 0.05;
                
                // 腿部轻微动作
                leftLeg.rotation.x = Math.sin(time * 2) * 0.1;
                rightLeg.rotation.x = Math.sin(time * 2 + Math.PI) * 0.1;
                
                // 整体上下移动
                this.position.y = Math.sin(time * 1.5) * 0.02;
            };

            person2.tick = function(time) {
                const head = this.userData.head;
                const leftArm = this.userData.leftArm;
                const rightArm = this.userData.rightArm;
                const scarf = this.userData.scarf;
                const leftLeg = this.userData.leftLeg;
                const rightLeg = this.userData.rightLeg;
                const leftGlove = this.userData.leftGlove;
                const rightGlove = this.userData.rightGlove;
                const hat = this.userData.hat;

                // 身体摆动
                this.rotation.x = Math.sin(time * 0.5 + Math.PI) * 0.08;
                
                // 头部动作（略微害的感觉）
                head.rotation.y = Math.sin(time * 0.8) * 0.15;
                head.rotation.x = Math.sin(time * 0.5) * 0.05 - 0.1;
                
                // 手臂动作（更温柔的动作）
                leftArm.rotation.z = Math.PI / 4 + Math.sin(time * 1.5) * 0.15;
                rightArm.rotation.z = -Math.PI / 4 + Math.sin(time * 1.5 + Math.PI) * 0.15;
                
                // 手套跟随手臂
                leftGlove.position.y = 0.5 + Math.sin(time * 1.5) * 0.08;
                rightGlove.position.y = 0.5 + Math.sin(time * 1.5 + Math.PI) * 0.08;
                
                // 围巾飘
                scarf.rotation.z = Math.sin(time * 2.5) * 0.15;
                
                // 帽子轻微摆动
                hat.rotation.z = Math.sin(time * 0.5 + Math.PI) * 0.05;
                
                // 腿部轻微动作
                leftLeg.rotation.x = Math.sin(time * 1.5) * 0.08;
                rightLeg.rotation.x = Math.sin(time * 1.5 + Math.PI) * 0.08;
                
                // 整体上下移动（与男生错开）
                this.position.y = Math.sin(time * 1.5 + Math.PI) * 0.02;
            };
        }

        function createPerson(options) {
            const person = new THREE.Group();

            // 创建身体（使用更圆润的形状）
            const body = new THREE.Mesh(
                new THREE.CapsuleGeometry(0.2, 0.3, 8, 16),
                new THREE.MeshPhysicalMaterial({ 
                    color: options.color,
                    clearcoat: 0.3,
                    clearcoatRoughness: 0.2,
                    metalness: 0.2,
                    roughness: 0.4
                })
            );
            body.position.y = 0.4;
            person.add(body);

            // 创建头部（更可爱的头型）
            const head = new THREE.Mesh(
                new THREE.SphereGeometry(0.18, 32, 32),
                new THREE.MeshPhysicalMaterial({ 
                    color: 0xffdbac,
                    clearcoat: 0.5,
                    clearcoatRoughness: 0.1,
                    metalness: 0.1,
                    roughness: 0.3
                })
            );
            head.position.y = 0.85;
            head.scale.x = 0.9; // 略微扁平的头型
            person.add(head);

            // 添加脸颊
            const cheekGeometry = new THREE.SphereGeometry(0.04, 16, 16);
            const cheekMaterial = new THREE.MeshStandardMaterial({ color: 0xff9999 });
            
            const leftCheek = new THREE.Mesh(cheekGeometry, cheekMaterial);
            leftCheek.position.set(-0.12, 0.85, 0.12);
            person.add(leftCheek);
            
            const rightCheek = new THREE.Mesh(cheekGeometry, cheekMaterial);
            rightCheek.position.set(0.12, 0.85, 0.12);
            person.add(rightCheek);

            // 添加眼睛
            const eyeGeometry = new THREE.SphereGeometry(0.02, 16, 16);
            const eyeMaterial = new THREE.MeshStandardMaterial({ color: 0x000000 });
            const eyeWhiteMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff });
            
            // 白色部分
            const leftEyeWhite = new THREE.Mesh(
                new THREE.SphereGeometry(0.035, 16, 16),
                eyeWhiteMaterial
            );
            leftEyeWhite.position.set(-0.08, 0.88, 0.15);
            person.add(leftEyeWhite);
            
            const rightEyeWhite = new THREE.Mesh(
                new THREE.SphereGeometry(0.035, 16, 16),
                eyeWhiteMaterial
            );
            rightEyeWhite.position.set(0.08, 0.88, 0.15);
            person.add(rightEyeWhite);
            
            // 黑色部分
            const leftEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
            leftEye.position.set(-0.08, 0.88, 0.17);
            person.add(leftEye);
            
            const rightEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
            rightEye.position.set(0.08, 0.88, 0.17);
            person.add(rightEye);

            // 添加帽子（更可爱的帽子）
            const hat = new THREE.Group();
            // 帽子主体
            const hatBase = new THREE.Mesh(
                new THREE.CylinderGeometry(0.2, 0.22, 0.15, 32),
                new THREE.MeshPhysicalMaterial({ 
                    color: options.hatColor || 0x333333,
                    clearcoat: 0.3,
                    roughness: 0.4
                })
            );
            // 帽子顶部
            const hatTop = new THREE.Mesh(
                new THREE.SphereGeometry(0.05, 16, 16),
                new THREE.MeshPhysicalMaterial({ 
                    color: 0xffffff,
                    clearcoat: 0.5,
                    roughness: 0.2
                })
            );
            hatTop.position.y = 0.1;
            // 帽子边缘
            const hatRim = new THREE.Mesh(
                new THREE.TorusGeometry(0.22, 0.02, 16, 32),
                hatBase.material
            );
            hatRim.position.y = -0.06;
            
            hat.add(hatBase, hatTop, hatRim);
            hat.position.y = 1.1;
            hat.rotation.x = -0.2; // 帽子稍微倾斜
            person.add(hat);

            // 添加围巾（更蓬松的围巾）
            const scarf = new THREE.Group();
            // 围巾主体
            const scarfMain = new THREE.Mesh(
                new THREE.TorusGeometry(0.12, 0.05, 16, 32),
                new THREE.MeshPhysicalMaterial({ 
                    color: options.scarf,
                    clearcoat: 0.3,
                    roughness: 0.6
                })
            );
            // 围巾垂下的部分
            const scarfEnd = new THREE.Mesh(
                new THREE.BoxGeometry(0.1, 0.3, 0.05),
                scarfMain.material
            );
            scarfEnd.position.set(0.15, -0.1, 0);
            scarfEnd.rotation.z = Math.PI / 6;
            
            const scarfEnd2 = new THREE.Mesh(
                new THREE.BoxGeometry(0.1, 0.2, 0.05),
                scarfMain.material
            );
            scarfEnd2.position.set(0.12, -0.15, 0);
            scarfEnd2.rotation.z = Math.PI / 4;
            
            scarf.add(scarfMain, scarfEnd, scarfEnd2);
            scarf.position.y = 0.7;
            scarf.rotation.x = Math.PI / 2;
            person.add(scarf);

            // 添加手臂（更圆润的手臂）
            const armGeometry = new THREE.CapsuleGeometry(0.035, 0.25, 8, 16);
            const armMaterial = new THREE.MeshPhysicalMaterial({ 
                color: options.color,
                clearcoat: 0.3,
                roughness: 0.4
            });
            
            const leftArm = new THREE.Mesh(armGeometry, armMaterial);
            leftArm.position.set(-0.28, 0.6, 0);
            leftArm.rotation.z = Math.PI / 4;
            person.add(leftArm);
            
            const rightArm = new THREE.Mesh(armGeometry, armMaterial);
            rightArm.position.set(0.28, 0.6, 0);
            rightArm.rotation.z = -Math.PI / 4;
            person.add(rightArm);

            // 添加手套
            const gloveGeometry = new THREE.SphereGeometry(0.04, 16, 16);
            const gloveMaterial = new THREE.MeshPhysicalMaterial({ 
                color: 0xffffff,
                clearcoat: 0.5,
                roughness: 0.3
            });
            
            const leftGlove = new THREE.Mesh(gloveGeometry, gloveMaterial);
            leftGlove.position.copy(leftArm.position);
            leftGlove.position.x -= 0.15;
            leftGlove.position.y -= 0.1;
            person.add(leftGlove);
            
            const rightGlove = new THREE.Mesh(gloveGeometry, gloveMaterial);
            rightGlove.position.copy(rightArm.position);
            rightGlove.position.x += 0.15;
            rightGlove.position.y -= 0.1;
            person.add(rightGlove);

            // 添加腿（更可爱的腿型）
            const legGeometry = new THREE.CapsuleGeometry(0.045, 0.2, 8, 16);
            const legMaterial = new THREE.MeshPhysicalMaterial({ 
                color: 0x222222,
                clearcoat: 0.3,
                roughness: 0.4
            });
            
            const leftLeg = new THREE.Mesh(legGeometry, legMaterial);
            leftLeg.position.set(-0.08, 0.15, 0);
            person.add(leftLeg);
            
            const rightLeg = new THREE.Mesh(legGeometry, legMaterial);
            rightLeg.position.set(0.08, 0.15, 0);
            person.add(rightLeg);

            // 添加靴子
            const bootGeometry = new THREE.CapsuleGeometry(0.05, 0.1, 8, 16);
            const bootMaterial = new THREE.MeshPhysicalMaterial({ 
                color: 0x111111,
                clearcoat: 0.5,
                roughness: 0.3
            });
            
            const leftBoot = new THREE.Mesh(bootGeometry, bootMaterial);
            leftBoot.position.set(-0.08, 0.05, 0);
            leftBoot.scale.set(1.2, 0.5, 1.2);
            person.add(leftBoot);
            
            const rightBoot = new THREE.Mesh(bootGeometry, bootMaterial);
            rightBoot.position.set(0.08, 0.05, 0);
            rightBoot.scale.set(1.2, 0.5, 1.2);
            person.add(rightBoot);

            // 设置位置和旋转
            person.position.set(options.position.x, options.position.y, options.position.z);
            person.rotation.y = options.rotation;

            // 添加阴影
            person.traverse(object => {
                if (object instanceof THREE.Mesh) {
                    object.castShadow = true;
                    object.receiveShadow = true;
                }
            });

            // 存储动画相关的引用
            person.userData.head = head;
            person.userData.leftArm = leftArm;
            person.userData.rightArm = rightArm;
            person.userData.scarf = scarf;
            person.userData.leftLeg = leftLeg;
            person.userData.rightLeg = rightLeg;
            person.userData.leftGlove = leftGlove;
            person.userData.rightGlove = rightGlove;
            person.userData.hat = hat;

            scene.add(person);
            return person;
        }

        // 添加堆雪人的痕迹
        function createSnowmanTraces() {
            // 添加脚印
            const footprints = [];
            for (let i = 0; i < 10; i++) {
                const footprint = new THREE.Mesh(
                    new THREE.CircleGeometry(0.08, 8),
                    new THREE.MeshStandardMaterial({
                        color: 0xeeeeee,
                        roughness: 1,
                        metalness: 0
                    })
                );
                
                // 创建蛇形路径的脚印
                const angle = i * 0.3;
                const radius = 2 + Math.sin(i * 0.5) * 0.5;
                footprint.position.set(
                    Math.cos(angle) * radius,
                    0.01,
                    Math.sin(angle) * radius
                );
                footprint.rotation.x = -Math.PI / 2;
                footprint.rotation.z = Math.random() * Math.PI;
                
                scene.add(footprint);
                footprints.push(footprint);
            }

            // 添加滚雪的痕迹
            const snowTrail = new THREE.Mesh(
                new THREE.PlaneGeometry(0.1, 1),
                new THREE.MeshStandardMaterial({
                    color: 0xeeeeee,
                    roughness: 1,
                    metalness: 0,
                    transparent: true,
                    opacity: 0.7
                })
            );
            snowTrail.rotation.x = -Math.PI / 2;
            snowTrail.position.y = 0.01;
            scene.add(snowTrail);
        }

        // 添加地板装饰的函数
        function createFloorDecorations() {
            // 添加小树枝和松果
            const twigCount = 15;
            for (let i = 0; i < twigCount; i++) {
                // 创建树枝
                const twig = new THREE.Group();
                
                // 主枝干
                const mainBranch = new THREE.Mesh(
                    new THREE.CylinderGeometry(0.02, 0.01, 0.3, 4),
                    new THREE.MeshStandardMaterial({ color: 0x4a2f1b })
                );
                mainBranch.rotation.z = Math.random() * Math.PI * 0.25;
                twig.add(mainBranch);

                // 添加小枝叶
                for (let j = 0; j < 4; j++) {
                    const leaf = new THREE.Mesh(
                        new THREE.CylinderGeometry(0.005, 0.002, 0.1, 3),
                        new THREE.MeshStandardMaterial({ 
                            color: new THREE.Color(0.1, 0.3 + Math.random() * 0.1, 0.1)
                        })
                    );
                    leaf.position.y = Math.random() * 0.2 - 0.1;
                    leaf.rotation.z = Math.random() * Math.PI;
                    leaf.rotation.x = Math.random() * Math.PI * 0.25;
                    twig.add(leaf);
                }

                // 随机位置
                const radius = 3 + Math.random() * 3;
                const angle = Math.random() * Math.PI * 2;
                twig.position.set(
                    Math.cos(angle) * radius,
                    0.02,
                    Math.sin(angle) * radius
                );
                twig.rotation.y = Math.random() * Math.PI;
                scene.add(twig);

                // 添加果
                if (Math.random() > 0.5) {
                    const pineCone = new THREE.Mesh(
                        new THREE.ConeGeometry(0.04, 0.08, 8),
                        new THREE.MeshStandardMaterial({ 
                            color: 0x3d2817,
                            roughness: 0.9
                        })
                    );
                    pineCone.position.set(
                        twig.position.x + Math.random() * 0.1,
                        0.04,
                        twig.position.z + Math.random() * 0.1
                    );
                    pineCone.rotation.x = Math.PI / 2;
                    scene.add(pineCone);
                }
            }

            // 添加小石头
            const rockCount = 20;
            for (let i = 0; i < rockCount; i++) {
                const rock = new THREE.Mesh(
                    new THREE.DodecahedronGeometry(0.05 + Math.random() * 0.05),
                    new THREE.MeshStandardMaterial({
                        color: 0x808080,
                        roughness: 0.8,
                        metalness: 0.2
                    })
                );
                
                const radius = 2.5 + Math.random() * 3;
                const angle = Math.random() * Math.PI * 2;
                rock.position.set(
                    Math.cos(angle) * radius,
                    0.02,
                    Math.sin(angle) * radius
                );
                rock.rotation.set(
                    Math.random() * Math.PI,
                    Math.random() * Math.PI,
                    Math.random() * Math.PI
                );
                rock.scale.set(
                    1 + Math.random() * 0.5,
                    0.8 + Math.random() * 0.3,
                    1 + Math.random() * 0.5
                );
                scene.add(rock);
            }

            // 添加雪堆装饰
            const snowPileCount = 12;
            for (let i = 0; i < snowPileCount; i++) {
                const snowPile = new THREE.Group();

                // 主雪堆
                const mainPile = new THREE.Mesh(
                    new THREE.SphereGeometry(0.2 + Math.random() * 0.2, 8, 6, 0, Math.PI * 2, 0, Math.PI / 2),
                    new THREE.MeshStandardMaterial({
                        color: 0xffffff,
                        roughness: 0.8,
                        metalness: 0.1
                    })
                );
                snowPile.add(mainPile);

                // 添加小雪堆
                const smallPileCount = Math.floor(Math.random() * 3) + 1;
                for (let j = 0; j < smallPileCount; j++) {
                    const smallPile = new THREE.Mesh(
                        new THREE.SphereGeometry(0.1 + Math.random() * 0.1, 8, 6, 0, Math.PI * 2, 0, Math.PI / 2),
                        mainPile.material
                    );
                    smallPile.position.set(
                        Math.random() * 0.2 - 0.1,
                        0,
                        Math.random() * 0.2 - 0.1
                    );
                    snowPile.add(smallPile);
                }

                // 放置雪堆
                const radius = 2 + Math.random() * 4;
                const angle = Math.random() * Math.PI * 2;
                snowPile.position.set(
                    Math.cos(angle) * radius,
                    0,
                    Math.sin(angle) * radius
                );
                snowPile.rotation.y = Math.random() * Math.PI;
                scene.add(snowPile);
            }

            // 添加闪光点
            const sparkleCount = 30;
            for (let i = 0; i < sparkleCount; i++) {
                const sparkle = new THREE.Mesh(
                    new THREE.PlaneGeometry(0.05, 0.05),
                    new THREE.MeshBasicMaterial({
                        color: 0xffffff,
                        transparent: true,
                        opacity: 0.6,
                        side: THREE.DoubleSide
                    })
                );

                const radius = 2 + Math.random() * 4;
                const angle = Math.random() * Math.PI * 2;
                sparkle.position.set(
                    Math.cos(angle) * radius,
                    0.01,
                    Math.sin(angle) * radius
                );
                sparkle.rotation.x = -Math.PI / 2;

                // 添加闪烁动画
                sparkle.userData.sparkle = true;
                sparkle.userData.speed = 0.5 + Math.random() * 2;
                scene.add(sparkle);
            }
        }

        // 修改雪地爱心的创建函数
        function createSnowHeartPattern() {
            // 调整爱心大小和位置
            const heartSize = 0.8;  // 减小爱心大小
            const segments = 60;    // 保持平滑度
            const heartPoints = [];
            
            // 生成爱心形状
            for (let i = 0; i < segments; i++) {
                const t = (i / segments) * Math.PI * 2;
                const x = heartSize * 16 * Math.pow(Math.sin(t), 3);
                const z = heartSize * (13 * Math.cos(t) - 5 * Math.cos(2*t) - 2 * Math.cos(3*t) - Math.cos(4*t));
                heartPoints.push(new THREE.Vector2(x, z));
            }

            const heartShape = new THREE.Shape(heartPoints);

            // 改进地印记材质
            const snowTrackMaterial = new THREE.MeshStandardMaterial({
                color: 0xf8f8f8,  // 稍微调亮
                roughness: 1,
                metalness: 0,
                transparent: true,
                opacity: 0.4,      // 降低不透明度使其更像雪地印记
                depthWrite: false
            });

            const heartTrack = new THREE.Mesh(
                new THREE.ShapeGeometry(heartShape),
                snowTrackMaterial
            );

            // 调整位置到雪地中心
            heartTrack.position.set(0, 0.011, 0);  // 轻微抬高以避免z-fighting
            heartTrack.rotation.x = -Math.PI / 2;
            scene.add(heartTrack);

            // 添加雪堆点缀
            const snowDotCount = 30;
            for (let i = 0; i < snowDotCount; i++) {
                const t = (i / snowDotCount) * Math.PI * 2;
                const x = heartSize * 16 * Math.pow(Math.sin(t), 3);
                const z = heartSize * (13 * Math.cos(t) - 5 * Math.cos(2*t) - 2 * Math.cos(3*t) - Math.cos(4*t));

                // 创建小雪堆
                const snowDot = new THREE.Mesh(
                    new THREE.SphereGeometry(0.03 + Math.random() * 0.04, 8, 6, 0, Math.PI * 2, 0, Math.PI / 2),
                    new THREE.MeshPhysicalMaterial({
                        color: 0xffffff,
                        roughness: 0.8,
                        metalness: 0.1,
                        clearcoat: 0.3
                    })
                );

                snowDot.position.set(x, 0.02, z);
                scene.add(snowDot);

                // 添加闪光点
                if (Math.random() > 0.6) {
                    const sparkle = new THREE.Mesh(
                        new THREE.PlaneGeometry(0.02, 0.02),
                        new THREE.MeshBasicMaterial({
                            color: 0xffffff,
                            transparent: true,
                            opacity: 0.5,
                            side: THREE.DoubleSide,
                            blending: THREE.AdditiveBlending
                        })
                    );
                    sparkle.position.set(
                        x + (Math.random() - 0.5) * 0.05,
                        0.03,
                        z + (Math.random() - 0.5) * 0.05
                    );
                    sparkle.rotation.x = -Math.PI / 2;
                    sparkle.userData.sparkle = true;
                    sparkle.userData.speed = 0.3 + Math.random() * 2;
                    scene.add(sparkle);
                }
            }

            // 添加脚印路径
            const footprintCount = 16;
            for (let i = 0; i < footprintCount; i += 2) {
                const progress = i / footprintCount;
                const radius = 2 - progress * 1.5;  // 缩小路径范围
                const baseAngle = Math.PI / 4 + progress * Math.PI / 2;
                
                // 左脚印
                const leftPrint = new THREE.Mesh(
                    new THREE.CircleGeometry(0.04, 8),
                    snowTrackMaterial
                );
                const leftAngle = baseAngle - 0.1;
                leftPrint.position.set(
                    Math.cos(leftAngle) * radius,
                    0.012,
                    Math.sin(leftAngle) * radius
                );
                leftPrint.rotation.x = -Math.PI / 2;
                leftPrint.rotation.z = leftAngle + Math.PI / 6;
                scene.add(leftPrint);
                
                // 右脚印
                const rightPrint = new THREE.Mesh(
                    new THREE.CircleGeometry(0.04, 8),
                    snowTrackMaterial
                );
                const rightAngle = baseAngle + 0.1;
                rightPrint.position.set(
                    Math.cos(rightAngle) * radius,
                    0.012,
                    Math.sin(rightAngle) * radius
                );
                rightPrint.rotation.x = -Math.PI / 2;
                rightPrint.rotation.z = rightAngle - Math.PI / 6;
                scene.add(rightPrint);
            }
        }

        // 添加音乐控制功能
        function initMusicControl() {
            const musicControl = document.querySelector('.music-control');
            const bgMusic = document.getElementById('bgMusic');
            let isMusicPlaying = false;

            musicControl.style.display = 'flex';
            
            musicControl.addEventListener('click', () => {
                if (isMusicPlaying) {
                    bgMusic.pause();
                    musicControl.querySelector('i').classList.remove('fa-volume-up');
                    musicControl.querySelector('i').classList.add('fa-volume-mute');
                } else {
                    bgMusic.play();
                    musicControl.querySelector('i').classList.remove('fa-volume-mute');
                    musicControl.querySelector('i').classList.add('fa-volume-up');
                }
                isMusicPlaying = !isMusicPlaying;
            });
        }

        // 添加自动相机动画
        let cameraAnimation;
        function startCameraAnimation() {
            const radius = 6;
            const height = 2;
            const speed = 0.2;
            
            cameraAnimation = setInterval(() => {
                if (!controls.enabled) {
                    const time = Date.now() * 0.001;
                    camera.position.x = Math.cos(time * speed) * radius;
                    camera.position.z = Math.sin(time * speed) * radius;
                    camera.position.y = height + Math.sin(time * 0.5) * 0.2;
                    camera.lookAt(0, 1, 0);
                }
            }, 16);
        }

        // 添加交互控制
        function initControls() {
            let isAutoRotating = true;
            
            window.addEventListener('keydown', (e) => {
                if (e.key === 'Space' || e.key === ' ') {
                    isAutoRotating = !isAutoRotating;
                    controls.enabled = !isAutoRotating;
                }
            });

            window.addEventListener('mousedown', () => {
                isAutoRotating = false;
                controls.enabled = true;
            });

            startCameraAnimation();
        }

        // 添加创建相框的函数
        function createPhotoFrames() {
            const photoUrls = [
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2F50c04600-4d53-05e4-443f-35e30435f05f%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1737640933&t=9decb8712fb5d6f7223838443127ca08',
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2F50c04600-4d53-05e4-443f-35e30435f05f%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1737640933&t=9decb8712fb5d6f7223838443127ca08',
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2F50c04600-4d53-05e4-443f-35e30435f05f%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1737640933&t=9decb8712fb5d6f7223838443127ca08',
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2F50c04600-4d53-05e4-443f-35e30435f05f%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1737640933&t=9decb8712fb5d6f7223838443127ca08',
                'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fci.xiaohongshu.com%2F50c04600-4d53-05e4-443f-35e30435f05f%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fci.xiaohongshu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1737640933&t=9decb8712fb5d6f7223838443127ca08'
            ];

            let currentPhotoIndex = 0;
            const photoViewer = document.querySelector('.photo-viewer');
            const photoViewerImg = photoViewer.querySelector('img');
            const closeBtn = photoViewer.querySelector('.close-btn');
            const prevBtn = photoViewer.querySelector('.prev-btn');
            const nextBtn = photoViewer.querySelector('.next-btn');
            const frames = [];

            // 关闭查看器
            function closePhotoViewer() {
                photoViewer.classList.remove('active');
                setTimeout(() => {
                    controls.enabled = true;
                }, 300);
            }

            // 显示指定索引的照片
            function showPhoto(index) {
                currentPhotoIndex = index;
                photoViewerImg.src = photoUrls[index];
                photoViewer.classList.add('active');
                controls.enabled = false;
            }

            // 切换到上一张照片
            function showPrevPhoto() {
                currentPhotoIndex = (currentPhotoIndex - 1 + photoUrls.length) % photoUrls.length;
                photoViewerImg.style.opacity = '0';
                setTimeout(() => {
                    photoViewerImg.src = photoUrls[currentPhotoIndex];
                    photoViewerImg.style.opacity = '1';
                }, 300);
            }

            // 切换到下一张照片
            function showNextPhoto() {
                currentPhotoIndex = (currentPhotoIndex + 1) % photoUrls.length;
                photoViewerImg.style.opacity = '0';
                setTimeout(() => {
                    photoViewerImg.src = photoUrls[currentPhotoIndex];
                    photoViewerImg.style.opacity = '1';
                }, 300);
            }

            // 绑定事件
            closeBtn.addEventListener('click', closePhotoViewer);
            prevBtn.addEventListener('click', showPrevPhoto);
            nextBtn.addEventListener('click', showNextPhoto);

            // 点击空白区域关闭
            photoViewer.addEventListener('click', (e) => {
                if (e.target === photoViewer) {
                    closePhotoViewer();
                }
            });

            // 键盘事件
            document.addEventListener('keydown', (e) => {
                if (!photoViewer.classList.contains('active')) return;
                
                switch(e.key) {
                    case 'Escape':
                        closePhotoViewer();
                        break;
                    case 'ArrowLeft':
                        showPrevPhoto();
                        break;
                    case 'ArrowRight':
                        showNextPhoto();
                        break;
                }
            });

            // 添加点击事件处理
            const raycaster = new THREE.Raycaster();
            const mouse = new THREE.Vector2();

            renderer.domElement.addEventListener('click', (event) => {
                mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
                mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;

                raycaster.setFromCamera(mouse, camera);
                const intersects = raycaster.intersectObjects(frames, true);

                if (intersects.length > 0) {
                    let clickedFrame = intersects[0].object;
                    // 查找父级相框
                    while (clickedFrame && !clickedFrame.userData.hasOwnProperty('photoIndex')) {
                        clickedFrame = clickedFrame.parent;
                    }
                    if (clickedFrame && clickedFrame.userData.hasOwnProperty('photoIndex')) {
                        showPhoto(clickedFrame.userData.photoIndex);
                    }
                }
            });

            const loadingManager = new THREE.LoadingManager();
            loadingManager.onLoad = function() {
                console.log('所有图片加载完成');
                document.querySelector('.loading').style.display = 'none';
            };
            loadingManager.onProgress = function(url, loaded, total) {
                console.log('加载进度:', Math.round(loaded/total * 100) + '%');
                const progressBar = document.querySelector('.progress-bar');
                if (progressBar) {
                    progressBar.style.width = (loaded/total * 100) + '%';
                }
            };
            loadingManager.onError = function(url) {
                console.error('图片加载失败:', url);
            };

            photoUrls.forEach((url, index) => {
                const loader = new THREE.TextureLoader(loadingManager);
                const photoTexture = loader.load(url);
                photoTexture.encoding = THREE.sRGBEncoding;

                // 创建相框
                const frameWidth = 0.3;
                const frameHeight = 0.4;
                const frameDepth = 0.02;

                // 相框背板
                const frameGeometry = new THREE.BoxGeometry(frameWidth, frameHeight, frameDepth);
                const frameMaterial = new THREE.MeshPhysicalMaterial({
                    color: 0xffffff,
                    metalness: 0.1,
                    roughness: 0.5,
                    clearcoat: 0.8
                });
                const frame = new THREE.Mesh(frameGeometry, frameMaterial);

                // 照片
                const photoGeometry = new THREE.PlaneGeometry(frameWidth * 0.9, frameHeight * 0.9);
                const photoMaterial = new THREE.MeshBasicMaterial({
                    map: photoTexture,
                    side: THREE.DoubleSide
                });
                const photo = new THREE.Mesh(photoGeometry, photoMaterial);
                photo.position.z = frameDepth / 2 + 0.001;
                frame.add(photo);

                // 添加背面照片
                const backPhoto = new THREE.Mesh(photoGeometry, photoMaterial.clone());
                backPhoto.position.z = -(frameDepth / 2 + 0.001);
                backPhoto.rotation.y = Math.PI; // 旋转180度
                frame.add(backPhoto);

                // 相框边框
                const borderMaterial = new THREE.MeshPhysicalMaterial({
                    color: 0xd4af37, // 金色边框
                    metalness: 0.8,
                    roughness: 0.2
                });

                // 添加四个边框
                const borderWidth = 0.02;
                const borders = [
                    new THREE.BoxGeometry(frameWidth + borderWidth, borderWidth, frameDepth * 1.5), // 上边框
                    new THREE.BoxGeometry(frameWidth + borderWidth, borderWidth, frameDepth * 1.5), // 下边框
                    new THREE.BoxGeometry(borderWidth, frameHeight + borderWidth, frameDepth * 1.5), // 左边框
                    new THREE.BoxGeometry(borderWidth, frameHeight + borderWidth, frameDepth * 1.5)  // 右边框
                ];

                borders.forEach((geometry, i) => {
                    const border = new THREE.Mesh(geometry, borderMaterial);
                    if (i === 0) border.position.y = frameHeight / 2; // 上边框
                    if (i === 1) border.position.y = -frameHeight / 2; // 下边框
                    if (i === 2) border.position.x = -frameWidth / 2; // 左边框
                    if (i === 3) border.position.x = frameWidth / 2; // 右边框
                    frame.add(border);
                });

                // 添加挂绳
                const stringGeometry = new THREE.CylinderGeometry(0.002, 0.002, 0.1, 8);
                const stringMaterial = new THREE.MeshStandardMaterial({ color: 0xcccccc });
                const string = new THREE.Mesh(stringGeometry, stringMaterial);
                string.position.y = frameHeight / 2 + 0.05;
                frame.add(string);

                // 设置相框位置
                const angle = (index / photoUrls.length) * Math.PI * 2;
                const radius = 1.2 + Math.random() * 0.2; // 增加半径，使相框分布更开
                const height = 1.2 + Math.random() * 1.2; // 调整高度范围
                
                frame.position.set(
                    Math.cos(angle) * radius,
                    height,
                    Math.sin(angle) * radius
                );

                // 让相框面向圣诞树中心
                frame.lookAt(0, frame.position.y, 0);
                // 添加一点随机旋转
                frame.rotation.y += (Math.random() - 0.5) * 0.5;
                frame.rotation.x += (Math.random() - 0.5) * 0.2;

                // 添加摆动动画
                frame.tick = function(time) {
                    this.rotation.y += Math.sin(time * 0.5) * 0.001;
                    this.rotation.x += Math.sin(time * 0.7) * 0.0005;
                    this.position.y = height + Math.sin(time + index) * 0.02;
                };

                // 存储相框索引
                frame.userData.photoIndex = index;
                frames.push(frame);

                scene.add(frame);
                scene.userData.animatedObjects.push(frame);
            });
        }

        // 加载纹理并初始化场景
        loadTextures()
            .then(() => {
                init();
                // 移除加载提示
                document.querySelector('.loading').style.display = 'none';
                // 初始化音乐控制
                initMusicControl();
                initControls(); // 添加控制初始化
            })
            .catch(error => {
                console.error('Error loading textures:', error);
                document.querySelector('.loading').textContent = '加载失败，请刷新页面重试';
            });
    </script>
</body>
</html>
